#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#define BUFSIZE 1024
#define err_exit(MSG) (perror(MSG), exit(1))

int main(int argc, char *argv[])
{
    /*声明文件指针*/
    FILE *from, *to;
    int cnt = 0;          //实际读取的数据
    char buffer[BUFSIZE]; //缓冲区
    /*检验参数个数*/
    if (argc != 3)
    {
        err_exit("Argument Error!");
    }
    //打开文件流
    from = fopen(argv[1], "r");
    to = fopen(argv[2], "w");
    /*检验文件流是否正常打开*/
    if (from == NULL || to == NULL)
    {
        err_exit("File open Failed!");
    }
    /*从from中读取写入to中*/
    while ((cnt = fread(buffer, sizeof(char), BUFSIZE, from)) > 0)
    {
        fwrite(buffer, sizeof(char), cnt, to);
    }
    /*关闭文件流*/
    fclose(from);
    fclose(to);
    return 0;
}